package com.hup.minicontroller.server.model;

import androidx.core.util.Consumer;

import java.util.ArrayList;

import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * app实时状态:
 * .设备状态
 * .app配置
 * .控制模块配置
 * .客户端session
 */
@Data
public class AppState {

    /**
     * 局域网服务端(wifi,热点)已启动
     */
    private boolean startedLan = false;
    /**
     * 蓝牙服务端已启动
     */
    private boolean startedBluetooth = false;

    private boolean wifiOn = false;
    private boolean apOn = false;
    private boolean bluetoothOn = false;

    private AppConfig appConfig = new AppConfig();

    private ControlConfig controlConfig = new ControlConfig();

    /**
     * 已上线客户端Session
     */
    @Getter(AccessLevel.PRIVATE)
    @Setter(AccessLevel.PRIVATE)
    private ArrayList<OnlineClientSession> lstOnlineClientSession = new ArrayList<>();

    /**
     * 读写client时都要保证线程安全;
     *
     * @apiNote 目前未观察到性能影响问题, 待观察
     */
    public synchronized void accessClient(Consumer<ArrayList<OnlineClientSession>> consumer) {
        consumer.accept(lstOnlineClientSession);
    }

    /**
     * @return 有无已上线的client
     */
    public boolean hasClient() {
        return !lstOnlineClientSession.isEmpty();
    }

}
